package com.winterwar.service.impl;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.winterwar.base.Convention;
import com.winterwar.dao.ConventionDAO;
import com.winterwar.service.ConventionManager;

public class ConventionManagerImpl implements ConventionManager {

	public Convention get(String conID) {
		Convention con = dao.get(Integer.valueOf(conID));
		if(con == null){
			log.warn("Convention with ID of " + conID + " does not exist.");
		}
		return con; 
	}

	public List getAll() {
		return dao.getAll();
	}

	public void remove(String conID) {
		log.info("ConID Passed to manager remove is: " + conID);
		dao.remove(Integer.valueOf(conID));
	}

	public Convention save(Convention convention) {
		dao.save(convention);
		return convention;
	}
	
	public void setDAO(ConventionDAO dao){
		this.dao = dao;
	}
	
	private static Log log = LogFactory.getLog(ConventionManager.class);
	private ConventionDAO dao;

	public Convention getCurrentCon() {
		List cons = dao.getCurrentCon();
		if(cons == null || cons.size() < 1 || ((Convention) cons.get(0)).getConID() == null || ((Convention) cons.get(0)).getConID().intValue() == 0){
			return null;
		}
		return (Convention) cons.get(0);
	}

}
